<template>
    <div class="drawerContainer">
        <el-form :model="propJson" label-width="auto" style="width: 100%">
            <el-form-item label="value-绑定参数">
                <el-select v-model="propJson.bindVariable" placeholder="参数名称" style="width: 100%">
                    <el-option v-for="info in commonParam" :label="info.variableName" :value="info.variableName" />
                </el-select>
            </el-form-item>

            <el-form-item label="html-绑定参数">
                <el-select v-model="propJson.htmlBindVariable" placeholder="参数名称" style="width: 100%">
                    <el-option v-for="info in commonParam" :label="info.variableName" :value="info.variableName" />
                </el-select>
            </el-form-item>

            <el-form-item label="编辑器高度">
                <el-input v-model="propJson.height" style="width: 100%" placeholder="编辑器高度" />
            </el-form-item>

            <el-form-item label="分栏设置">
                <el-radio-group v-model="propJson.subfield">
                    <el-radio label="double">双栏</el-radio>
                    <el-radio label="one">单栏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="默认开启分区">
                <el-radio-group v-model="propJson.defaultOpen">
                    <el-radio label="edit">编辑栏</el-radio>
                    <el-radio label="preview">预览栏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="placeholder数据">
                <el-input v-model="propJson.placeholder" style="width: 100%" placeholder="placeholder数据" />
            </el-form-item>

            <el-form-item label="是否展示背景阴影">
                <el-radio-group v-model="propJson.isBoxShadow">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否允许编辑">
                <el-radio-group v-model="propJson.editable">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="代码是否高亮">
                <el-radio-group v-model="propJson.ishljs">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否展示工具栏">
                <el-radio-group v-model="propJson.toolbarsFlag">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-divider v-if="propJson.toolbarsFlag">工具栏设置</el-divider>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 粗体">
                <el-radio-group v-model="propJson.toolbars.bold">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 斜体">
                <el-radio-group v-model="propJson.toolbars.italic">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 标题">
                <el-radio-group v-model="propJson.toolbars.header">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 下划线">
                <el-radio-group v-model="propJson.toolbars.underline">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 中划线">
                <el-radio-group v-model="propJson.toolbars.strikethrough">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 标记">
                <el-radio-group v-model="propJson.toolbars.mark">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 上角标">
                <el-radio-group v-model="propJson.toolbars.superscript">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 下角标">
                <el-radio-group v-model="propJson.toolbars.subscript">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 引用">
                <el-radio-group v-model="propJson.toolbars.quote">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 有序列表">
                <el-radio-group v-model="propJson.toolbars.ol">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 无序列表">
                <el-radio-group v-model="propJson.toolbars.ul">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 链接">
                <el-radio-group v-model="propJson.toolbars.link">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 图片链接">
                <el-radio-group v-model="propJson.toolbars.imagelink">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - code">
                <el-radio-group v-model="propJson.toolbars.code">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 表格">
                <el-radio-group v-model="propJson.toolbars.table">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 全屏编辑">
                <el-radio-group v-model="propJson.toolbars.fullscreen">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 沉浸式阅读">
                <el-radio-group v-model="propJson.toolbars.readmodel">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 展示html源码">
                <el-radio-group v-model="propJson.toolbars.htmlcode">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 帮助">
                <el-radio-group v-model="propJson.toolbars.help">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 上一步">
                <el-radio-group v-model="propJson.toolbars.undo">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 下一步">
                <el-radio-group v-model="propJson.toolbars.redo">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 清空">
                <el-radio-group v-model="propJson.toolbars.trash">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 保存">
                <el-radio-group v-model="propJson.toolbars.save">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 导航目录">
                <el-radio-group v-model="propJson.toolbars.navigation">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 左对齐">
                <el-radio-group v-model="propJson.toolbars.alignleft">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 居中">
                <el-radio-group v-model="propJson.toolbars.aligncenter">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 右对齐">
                <el-radio-group v-model="propJson.toolbars.alignright">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 单双栏模式">
                <el-radio-group v-model="propJson.toolbars.subfield">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item v-if="propJson.toolbarsFlag" label="工具栏 - 预览">
                <el-radio-group v-model="propJson.toolbars.preview">
                    <el-radio :label="true">展示</el-radio>
                    <el-radio :label="false">隐藏</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否关联外部目录">
                <el-radio-group v-model="propJson.isRelateMarkDownDir">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="markDown容器对象关联变量" v-if="propJson.isRelateMarkDownDir">
                <el-select v-model="propJson.markDownVariable" placeholder="参数名称" style="width: 100%">
                    <el-option v-for="info in commonParam" :label="info.variableName" :value="info.variableName" />
                </el-select>
            </el-form-item>

            <el-divider>MarkDown文本内容设置</el-divider>
            <CommonThirdServiceValue :actionInfo="propJson.actionInfo ? propJson.actionInfo : {}" :commonParam="commonParam" />

            <el-divider>上传图片请求配置</el-divider>

            <el-form-item label="调用方式">
                <!-- MSSA Microsoft Service Share Api -->
                <!-- MSOA Microsoft Service Owned Api -->
                <!-- RTSA RestTemplate Service Share Api -->
                <el-radio-group v-model="propJson.doUploadAction.apiType">
                    <el-radio label="MSSA">微服务共享API</el-radio>
                    <el-radio label="MSOA">微服务自有API</el-radio>
                    <el-radio label="RTSA">通用透传API</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="服务地址">
                <el-input v-model="propJson.doUploadAction.apiPath" style="width: 100%" placeholder="服务地址" />
            </el-form-item>

            <el-form-item label="请求方式">
                <el-radio-group v-model="propJson.doUploadAction.apiMethod">
                    <el-radio label="GET">GET请求</el-radio>
                    <el-radio label="POST">POST请求</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="返回URL设置">
                <el-input v-model="propJson.returnUrlJsonPath" style="width: 100%" placeholder="$." />
            </el-form-item>

            <el-collapse>
                <el-collapse-item :name="index" v-for="(item, index) in propJson.imageInnerVariable">
                    <template #title>
                        <div class="collapseTitle">
                            <span>{{item.name}}</span>
                        </div>
                    </template>
                    <el-form-item label="参数类型">
                        <el-radio-group v-model="item.type">
                            <el-radio label="custom">自定义</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="赋值字段" v-if="item.type === 'custom'">
                        <el-input v-model="item.variableName" style="width: 100%" placeholder="$."/>
                    </el-form-item>
                </el-collapse-item>
            </el-collapse>


            <div style="display: flex; justify-content: center; align-items: center; margin-top: 3%;">
                <el-button type="primary" class="addCollapse" size="small" @click="addRequestVariable(propJson.doUploadAction)">添加请求入参</el-button>
            </div>

            <el-form label-width="auto" style="width: 100%">
                <el-collapse>
                    <el-collapse-item :name="paramIndex" v-for="(paramItem, paramIndex) in propJson.doUploadAction.apiParamList">
                        <template #title>
                            <div class="collapseTitle">
                                <span>参数 {{(paramIndex + 1)}}</span>
                                <el-button type="danger" plain size="small" style="margin-left: 20px" @click.stop="deleteRequestVariable(propJson.doUploadAction, paramIndex)">删除</el-button>
                            </div>
                        </template>
                        <el-form-item label="参数类型">
                            <el-radio-group v-model="paramItem.type">
                                <el-radio label="custom">自定义</el-radio>
                                <el-radio label="variable">关联变量</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="参数名称">
                            <el-input v-model="paramItem.variableName" style="width: 100%"/>
                        </el-form-item>
                        <el-form-item label="参数值" v-if="paramItem.type === 'custom'">
                            <el-input v-model="paramItem.variableValue" style="width: 100%">
                                <template #prepend>
                                    <el-select v-model="paramItem.variableType" placeholder="Select" style="width: 115px">
                                        <el-option label="字符串" value="String" />
                                        <el-option label="数组" value="Array" />
                                        <el-option label="对象" value="Object" />
                                    </el-select>
                                </template>
                            </el-input>
                        </el-form-item>

                        <el-form-item label="变量名称" v-if="paramItem.type === 'variable'">
                            <el-select v-model="paramItem.variableParamName" placeholder="变量名称" style="width: 100%">
                                <el-option v-for="info in commonParam" :label="info.variableName" :value="info.variableName" />
                            </el-select>
                        </el-form-item>
                    </el-collapse-item>
                </el-collapse>
            </el-form>
        </el-form>
    </div>
</template>

<script name="MarkDownDrawer" setup lang="ts">
import CommonThirdServiceValue from "@/components/lowcode/service/CommonThirdServiceValue.vue"
import {computed, defineProps} from "vue";
import {useLowCodeStore} from "@/stores/lowcode/lowcode";

let props = defineProps(['commonParam']);

let commonParam = computed(() => {return props['commonParam']})

let propJson = computed(() => {return useLowCodeStore().lowCodeDrawerJsonInfo});

function addRequestVariable(item) {
    if (!item.apiParamList) {
        item.apiParamList = []
    }
    let variableInfo = {variableName: "", variableValue: "", type: "custom", variableType: "String", variableParamName: ""}
    item.apiParamList.push(variableInfo)
}

function deleteRequestVariable(item, index) {
    // 删除数组中的数据
    item.apiParamList.splice(index, 1);
}
</script>

<style scoped lang="less">

</style>